﻿Imports AFS.Aspnet.Collaboration.Site.ArbAuf
Imports AFS.Aspnet.Collaboration.Site.MandateAufstellung
Imports AFS.Aspnet.Collaboration.Site.GPSBilderDatenbank

' HINWEIS: Mit dem Befehl "Umbenennen" im Kontextmenü können Sie den Klassennamen "AFSForMetroService" sowohl im Code als auch in der SVC-Datei und der Konfigurationsdatei ändern.
' HINWEIS: Wählen Sie zum Starten des WCF-Testclients zum Testen dieses Diensts AFSForMetroService.svc oder AFSForMetroService.svc.vb im Projektmappen-Explorer aus, und starten Sie das Debuggen.

'Version: 	deploy v8.8.1.1

Public Class AFSForMetroService
    Implements IAFSForMetroService



    Public NoMandateDB As Boolean = False
    Public NoDB As Boolean = False
    Public NoGPSBilderDB As Boolean = False

    Sub New()
        If listofmandate.Count = 0 Then
            ' RefreshList()
            AutomaticUploadToBackYardServer.InitTimer()
        End If

        Dim initPathDB = DbPath()
        Dim InitPathMandate = MandateDBPath()
        Dim InitGPSBilderDB = GPSBilderPath()

        If initPathDB <> "" Then
            Dim ff As New SQLite.SQLiteConnectionStringBuilder
            ff.ConnectionString = "DbLinqProvider=Sqlite ; data source=" & DbPath()

            Dim con As New SQLite.SQLiteConnection(ff.ToString)
            db = New AFS.Aspnet.Collaboration.Site.ArbAuf.Main(con)
        Else
            My.Computer.FileSystem.WriteAllText(files, "Init ArbeitsaufzeichnungenDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            NoDB = True
        End If

        If InitPathMandate <> "" Then
            Dim mand As New SQLite.SQLiteConnectionStringBuilder
            mand.ConnectionString = "DbLinqProvider=Sqlite ; data source=" & MandateDBPath()

            Dim mandcon As New SQLite.SQLiteConnection(mand.ToString)
            mandateDb = New MandateAufstellung.Main(mandcon)

            listofmandate = Me.RetrieveAllSaveMandate
        Else
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            NoMandateDB = True
        End If

        If InitGPSBilderDB <> "" Then
            Dim gps As New SQLite.SQLiteConnectionStringBuilder
            gps.ConnectionString = "DbLinqProvider=Sqlite ; data source=" & GPSBilderPath()

            If System.IO.File.Exists(GPSBilderPath) Then
                My.Computer.FileSystem.WriteAllText(files, "xxxxxxxxx" & vbCrLf & "Init GPSBilderDB okay...." & Date.Now.ToString & vbCrLf & "xxxxxxx" & ";" & vbCrLf, True)
            Else
                My.Computer.FileSystem.WriteAllText(files, "xxxxxxxxx" & vbCrLf & "Init GPSBilderDBpathfile not found" & Date.Now.ToString & vbCrLf & "xxxxxxx" & ";" & vbCrLf, True)
            End If

            Dim conaa As New SQLite.SQLiteConnection(gps.ToString)
            gpsdb = New GPSBilderDatenbank.Main(conaa)
        Else
            My.Computer.FileSystem.WriteAllText(files, "Init GPSBilderDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            NoGPSBilderDB = True
        End If



    End Sub

#Region "Mandate"

    Public Function RetrieveAllSaveMandate() As List(Of MandateAnzahlen) Implements IAFSForMetroService.RetrieveAllSaveMandate
        ' RefreshList()
        If NoMandateDB = False Then
            Dim a = (From b In mandateDb.MandateAnzahlen
                    Select b).ToList

            listofmandate = a

            Return listofmandate
        Else
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return Nothing
        End If
    End Function

    Public Function AddNewMandate(a As List(Of MandateAnzahlen)) As Boolean Implements IAFSForMetroService.AddNewMandate
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Try
            mandateDb.MandateAnzahlen.InsertAllOnSubmit(a)
            mandateDb.SubmitChanges()
            Return True
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "AddNewMandate error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try
    End Function

    Public Sub EditMandat(Mandat As MandateAnzahlen) Implements IAFSForMetroService.EditMandat
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Exit Sub
        End If

        Try
            Dim a = From b In mandateDb.MandateAnzahlen
                    Where b.ID = Mandat.ID Or b.Datum = Mandat.Datum
                    Select b


            mandateDb.MandateAnzahlen.DeleteAllOnSubmit(a)
            mandateDb.MandateAnzahlen.InsertOnSubmit(Mandat)
            mandateDb.SubmitChanges()
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "EditMandate error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
        End Try

    End Sub

    Public Function SearchForMandate(datum As String, rayon As String, type As String) As List(Of MandateAnzahlen) Implements IAFSForMetroService.SearchForMandate
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return Nothing
        End If
        Try
            Return search(datum, rayon, type)
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "SearchForMandate error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return New List(Of MandateAnzahlen)
        End Try

    End Function

    Public Function DeleteMandatFromXML(ByVal id As String) As Boolean Implements IAFSForMetroService.DeleteMandatFromXML
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Try
            Dim a = From b In mandateDb.MandateAnzahlen
                    Where b.ID = id
                    Select b

            mandateDb.MandateAnzahlen.DeleteAllOnSubmit(a)
            mandateDb.SubmitChanges()


            Return CheckDeletionById(id)
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "DeleteMandat error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try

    End Function

    Private Function CheckDeletionById(ByVal id As String) As Boolean
        Dim a = From b In mandateDb.MandateAnzahlen
                Where b.ID = id
                Select b

        If a.Count = 0 Then
            Return True
        Else
            Return False
        End If
    End Function

    Public Function DeleteMandateByDates(dates As String) As Object Implements IAFSForMetroService.DeleteMandateByDates
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Try
            Dim a = From b In mandateDb.MandateAnzahlen
                    Where b.Datum = dates
                    Select b

            mandateDb.MandateAnzahlen.DeleteAllOnSubmit(a)
            mandateDb.SubmitChanges()

            Return True
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "deleteMandateByDates error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False

        End Try
    End Function

    Public Function AddNewMandat(aa As MandateAnzahlen) As Boolean Implements IAFSForMetroService.AddNewMandat
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init MandateDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Try
            If aa.ID Is Nothing Or aa.ID = "" Then
                aa.ID = System.Guid.NewGuid.ToString

                Dim a = From b In mandateDb.MandateAnzahlen
                        Where b.Datum = aa.Datum
                        Select b

                If a.Count = 0 Then

                    mandateDb.MandateAnzahlen.InsertOnSubmit(aa)
                    mandateDb.SubmitChanges()
                    Return True
                Else
                    EditMandat(aa)
                    Return True
                End If

            Else
                Dim ff = From a In mandateDb.MandateAnzahlen
                         Where a.ID = aa.ID Or a.Datum = aa.Datum
                         Select a

                If ff.Count = 0 Then
                    mandateDb.MandateAnzahlen.InsertOnSubmit(aa)
                    mandateDb.SubmitChanges()
                    Return True
                Else
                    EditMandat(aa)
                    Return True
                End If
            End If

        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "AddNewMandat error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try
    End Function

    Public Function ReadStatusFile() As String Implements IAFSForMetroService.ReadStatusFile
        Return AutomaticUploadToBackYardServer.ReadStatusFile
    End Function

    Public Function ClearMandateTable() As Boolean Implements IAFSForMetroService.CleareMandateTable
        Try
            Dim ff = (From b In mandateDb.MandateAnzahlen).ToList
            My.Computer.FileSystem.WriteAllText(files, "clear MandateDB: " & ff.Count & ";" & vbCrLf, True)
            For Each a In ff

                mandateDb.MandateAnzahlen.DeleteOnSubmit(a)
            Next
            Return CheckClearancy()
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "clear MandateDB failed" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & ";" & vbCrLf, True)
            Return False
        End Try

    End Function


    Private Function CheckClearancy()
        If mandateDb.MandateAnzahlen.Count = 0 Then
            Return True
        Else
            Return False
        End If
    End Function
#End Region

#Region "WorkdayAddance"

    Public Function AddNewWorkDay(workday As ArbAuf.Arbeitsaufzeichnung) As Boolean Implements IAFSForMetroService.AddNewWorkDay
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If



        Try
            Dim a = From b In db.Arbeitsaufzeichnung
                    Where b.Datum = workday.Datum
                    Select b

            If a.Count = 0 Then

                db.Arbeitsaufzeichnung.InsertOnSubmit(workday)
                db.SubmitChanges()
                Return True
            Else
                Return EditWorkDay(workday)
            End If
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "AddNewWorkDay error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try



    End Function

    Public Function DeleteWorkDay(id As String) As Boolean Implements IAFSForMetroService.DeleteWorkDay
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Try
            Dim a = From b In db.Arbeitsaufzeichnung
                    Where b.ID = id
                    Select b

            If a IsNot Nothing Then
                Try
                    db.Arbeitsaufzeichnung.DeleteAllOnSubmit(a)
                    db.SubmitChanges()
                    Return True
                Catch
                    Return False
                End Try

            Else
                Return False
            End If
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "DeleteWorkDay(id) error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try

    End Function

    Public Function EditWorkDay(eWorkday As ArbAuf.Arbeitsaufzeichnung) As Boolean Implements IAFSForMetroService.EditWorkDay
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Dim a = From b In db.Arbeitsaufzeichnung
                Where b.ID = eWorkday.ID Or b.Datum = eWorkday.Datum
                Select b
        Try

            For Each b In a
                Me.DeleteWorkDay(b.ID)
            Next


            Return Me.AddNewWorkDay(eWorkday)
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "EditWorkDay error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try

    End Function

    Public Function EnumerateAllWorkdays() As List(Of ArbAuf.Arbeitsaufzeichnung) Implements IAFSForMetroService.EnumerateAllWorkdays
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return Nothing
        End If

        Try
            Dim a = (From b In db.Arbeitsaufzeichnung
            Select b).ToList

            Return a
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "AllWorkday Enum error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return New List(Of ArbAuf.Arbeitsaufzeichnung)
        End Try

    End Function

    Public Function EnumerateWorkdayForMonth(MonthNumber As String) As List(Of ArbAuf.Arbeitsaufzeichnung) Implements IAFSForMetroService.EnumerateWorkdayForMonth
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return Nothing
        End If
        Try
            Dim a = (From b In db.Arbeitsaufzeichnung
                    Where b.Monat = MonthNumber
                    Select b).ToList

            Return a
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "WorkdayForMonth Enum error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return New List(Of ArbAuf.Arbeitsaufzeichnung)
        End Try

    End Function

    Public Function ClearWorkdayTable() As Boolean Implements IAFSForMetroService.ClearWorkDayTable
        Try
            Dim ff = (From a In db.Arbeitsaufzeichnung).ToList

            db.Arbeitsaufzeichnung.DeleteAllOnSubmit(ff)
            Return CheckClearancyWorkday()
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "clear MandateDB failed" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & ";" & vbCrLf, True)
            Return False
        End Try
    End Function

    Private Function CheckClearancyWorkday()
        If db.Arbeitsaufzeichnung.Count = 0 Then
            Return True
        Else
            Return False
        End If
    End Function

#End Region


#Region "ArbeitsTypen"
    Public Function AddArbeitsType(typ As Typen) As Boolean Implements IAFSForMetroService.AddArbeitsType
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Try
            Dim a = From b In db.Typen
                    Where b.Name = typ.Name
                    Select b

            If a.Count = 0 Then
                db.Typen.InsertOnSubmit(typ)
                db.SubmitChanges()
                Return True
            Else
                Return EditArbeitType(typ)
            End If
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "AddArbeitsType error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try

    End Function

    Public Function DeleteArbeitsType(type As Typen) As Boolean Implements IAFSForMetroService.DeleteArbeitsType
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Dim a = From b In db.Typen
                Where b.ID
                Select b
        Try
            If a IsNot Nothing Then
                db.Typen.DeleteAllOnSubmit(a)
                db.SubmitChanges()
                Return True
            Else
                Return False
            End If

        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "error deleteArbeitsTypen" & Date.Now.ToString & " " & ex.Message.ToString & " " & ex.Source.ToString & " " & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try
    End Function

    Public Function EditArbeitType(type As Typen) As Boolean Implements IAFSForMetroService.EditArbeitType
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Dim a = From b In db.Typen
                Where b.ID = type.ID Or b.Name = type.Name
                Select b

        Try
            If a IsNot Nothing Then
                db.Typen.DeleteAllOnSubmit(a)
            End If

            db.Typen.InsertOnSubmit(type)
            db.SubmitChanges()
            Return True
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "EditArbeitstype error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return False
        End Try

    End Function

    Public Function EnumerateArbeitsTypen() As List(Of Typen) Implements IAFSForMetroService.EnumerateArbeitsTypen
        If NoMandateDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init ArbAufDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return Nothing
        End If
        Try
            Dim a = (From b In db.Typen
                    Select b).ToList

            Return a
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "ArbeitsTypen Enum error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return New List(Of Typen)
        End Try
    End Function

    Public Function ClearTypenTable() As Boolean Implements IAFSForMetroService.ClearTypenTable
        Try
            Dim ff = (From a In db.Typen
                      Select a).ToList

            db.Typen.DeleteAllOnSubmit(ff)
            db.SubmitChanges()
            Return CheckClearancyTypen()
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "clear MandateDB failed" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & ";" & vbCrLf, True)
            Return False
        End Try

    End Function

    Private Function CheckClearancyTypen() As Boolean
        If db.Typen.Count = 0 Then
            Return True
        Else
            Return False
        End If
    End Function

#End Region

#Region "db tasks"

    Public Function DownloadDbFromBackServerManual() As Boolean Implements IAFSForMetroService.DownloadDbFromBackServerManual
        Dim retval = DownloadDatabaseFileFromBackFallServer()
        If retval Then
            InitArbeitsaufzeichnungenDBFile()
        End If
        Return retval
    End Function

    Public Function DownloadMandateDbFromBackServerManual() As Boolean Implements IAFSForMetroService.DownloadMandateDbFromBackServerManual
        Dim retval = DownloadMandateFileFromBackFallServer()
        If retval Then
            InitMandateDBFile()
        End If
        Return retval
    End Function

    Public Function UploadDBToBackServerManual() As Boolean Implements IAFSForMetroService.UploadDBToBackServerManual
        Dim retval = UploadDatabaseFileToBackFallServer()
        Return retval
    End Function

    Public Function UploadMandateDbToBackServerManual() As Boolean Implements IAFSForMetroService.UploadMandateDbToBackServerManual
        Dim retval = UploadMandateFileToBackFallServer()
        Return retval
    End Function
#End Region



#Region "GPSBilder"
    Public Function AddGPSBild(typ As GpspIcturesTable) As Boolean Implements IAFSForMetroService.AddGPSBild
        If NoGPSBilderDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init GPSDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Dim a = (From b In gpsdb.GpspIcturesTable
                Where b.Datum = typ.Datum And b.CreatedTime = typ.CreatedTime
                Select b).FirstOrDefault

        If a IsNot Nothing Then
            Return EditGPSBild(typ)
        Else
            Try
                typ.ID = System.Guid.NewGuid.ToString
                gpsdb.GpspIcturesTable.InsertOnSubmit(typ)
                gpsdb.SubmitChanges()
                Return True
            Catch ex As Exception
                My.Computer.FileSystem.WriteAllText(files, "AddGPSBild Enum error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
                Return False
            End Try
        End If
    End Function

    Public Function ClearGPSBilderTable() As Boolean Implements IAFSForMetroService.ClearGPSBilderTable
        If NoGPSBilderDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init GPSDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Dim ff = EnumerateGPSBild()

        Try
            gpsdb.GpspIcturesTable.DeleteAllOnSubmit(ff)
            gpsdb.SubmitChanges()
            Return True
        Catch
            Return False
        End Try
    End Function

    Public Function DeleteGPSBild(type As GpspIcturesTable) As Boolean Implements IAFSForMetroService.DeleteGPSBild
        If NoGPSBilderDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init GPSDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Dim a = From b In gpsdb.GpspIcturesTable
                Where b.ID = type.ID
                Select b

        If a.Count > 0 Then
            Try
                gpsdb.GpspIcturesTable.DeleteAllOnSubmit(a)
                gpsdb.SubmitChanges()
                Return True
            Catch ex As Exception
                My.Computer.FileSystem.WriteAllText(files, "GPSBild delete error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
                Return False
            End Try
        Else
            Return False
        End If
    End Function

    Public Function EditGPSBild(type As GpspIcturesTable) As Boolean Implements IAFSForMetroService.EditGPSBild
        If NoGPSBilderDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init GPSDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return False
        End If

        Dim a = From b In gpsdb.GpspIcturesTable
                Where b.ID = type.ID
                Select b

        For Each c In a
            Try
                With c
                    .Datum = type.Datum
                    .CreatedTime = type.CreatedTime
                    .OnlineSourcePath = type.OnlineSourcePath
                    .UploadFileName = type.UploadFileName
                End With
                gpsdb.SubmitChanges()
                Return True
            Catch ex As Exception
                My.Computer.FileSystem.WriteAllText(files, "GPSBild Edit error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
                Return False
            End Try

        Next
    End Function

    Public Function EnumerateGPSBild() As List(Of GpspIcturesTable) Implements IAFSForMetroService.EnumerateGPSBild
        If NoGPSBilderDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init GPSDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return New List(Of GpspIcturesTable)
        End If
        Try
            Dim retlist As New List(Of GpspIcturesTable)
            Dim nlist = From b In gpsdb.GpspIcturesTable
                        Select b

            For Each a In nlist
                retlist.Add(a)
            Next

            Return retlist
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "GPSDB Enum error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return New List(Of GpspIcturesTable)
        End Try
    End Function

    Public Function EnumerateGPSBildByValues(Datum As String, Time As String) As List(Of GpspIcturesTable) Implements IAFSForMetroService.EnumerateGPSBildByValues
        If NoGPSBilderDB Then
            My.Computer.FileSystem.WriteAllText(files, "Init GPSDB failed" & Date.Now.ToString & ";" & vbCrLf, True)
            Return New List(Of GpspIcturesTable)
        End If
        Try
            Dim query As IEnumerable(Of GpspIcturesTable) = EnumerateGPSBild()
            If Datum <> "" Then
                query = query.Where(Function(a As GpspIcturesTable)
                                        If a.Datum.Equals(Datum) Then
                                            Return True
                                        Else
                                            Return False
                                        End If
                                    End Function)
            End If

            If Time <> "" Then
                query = query.Where(Function(a As GpspIcturesTable)
                                        If a.CreatedTime.Equals(Time) Then
                                            Return True
                                        Else
                                            Return False
                                        End If
                                    End Function)
            End If

            Dim retlist As New List(Of GpspIcturesTable)
            For Each g In query
                retlist.Add(g)
            Next
            Return retlist
        Catch ex As Exception
            My.Computer.FileSystem.WriteAllText(files, "GPSDB Enum error" & Date.Now.ToString & vbCrLf & ex.Message.ToString & vbCrLf & ex.Source.ToString & vbCrLf & ex.StackTrace.ToString & ";" & vbCrLf, True)
            Return New List(Of GpspIcturesTable)
        End Try
    End Function

#End Region
End Class
